<%= section_panel "Releases#{' & Deployments' if @environment}",
                  :width    => 'single',
                  :position => 'left pinnable',
                  :menu     => @environment ? [link_to_function(icon('download'), "render_modal('deployment_list_download_modal')", :class => 'btn btn-mini')] : nil do %>
  <%= timeline_list([],
                    :paginate => {:url  => @environment ?
                                               page_assembly_transition_environment_timeline_path(@assembly, @environment) :
                                               page_assembly_design_timeline_path(@assembly),
                                  :size => 20},
                    :toolbar  => @environment ? {} : {:quick_filters => nil}) %>
<% end %>

<div id="timeline_details"></div>

<% if @environment %>
  <div id="deployment_list_download_modal" class="modal hide">
    <div class="modal-header">
      <h3>Download list of deployments?</h3>
    </div>
    <div class="modal-body">
      <p>You can export a list of past deployments for a given time period.</p>
      <br>
      <%= form_tag assembly_transition_environment_deployments_path(@assembly, @environment),
                   :method => :get,
                   :target => '_blank',
                   :class  => 'form-horizontal' do %>
        <div class="control-group">
          <%= label_tag :deploymentListStartTime, 'From:', :class => 'control-label' %>
          <div class="controls">
            <%= date_field_tag :start, Date.today.beginning_of_year, :required => true %>
          </div>
        </div>
        <div class="control-group">
          <%= label_tag :deploymentListEndTime, 'To:', :class => 'control-label' %>
          <div class="controls">
            <%= date_field_tag :end, Date.today.last_month.end_of_month, :required => true %>
          </div>
        </div>
        <%= hidden_field_tag :format, 'csv' %>
      <% end %>
    </div>

    <div class="modal-footer">
      <%= link_to_function(raw(icon('times', 'cancel')), 'hide_modal()', :class => 'btn btn-danger') %>
      <div class="btn-group">
        <a class="btn btn-success dropdown-toggle" data-toggle="dropdown" href="#">
          <%= icon('download', 'ok') %> <span class="caret"></span>
        </a>
        <ul class="dropdown-menu">
          <li><%= link_to_function(icon(site_icon(:yaml), content_tag(:small, 'to YAML'), 'faw-fw'), 'donwload_deployment_list("yaml")') %></li>
          <li><%= link_to_function(icon(site_icon(:json), content_tag(:small, 'to JSON'), 'faw-fw'), 'donwload_deployment_list("json")') %></li>
          <li><%= link_to_function(icon(site_icon(:csv), content_tag(:small, 'to CSV'), 'faw-fw'), 'donwload_deployment_list("csv")') %></li>
        </ul>
      </div>
    </div>
  </div>
  <script>
    window.donwload_deployment_list = function (format) {
      $j("#deployment_list_download_modal input#format").val(format);
      hide_modal();
      $j("#deployment_list_download_modal form").submit()
    }
  </script>
<% end %>

